package es.uc3m.setichat.format;

import java.util.ArrayList;

import es.uc3m.setichat.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ViewContact extends ArrayAdapter<Contacto> {
	
	protected Activity context;
    protected ArrayList <Contacto> datos;

    public ViewContact(Activity context, ArrayList <Contacto> datos) {
        super(context, R.layout.view_contact, datos);
        this.context = context;
        this.datos=datos;
    }

    static class ViewHolder {
        TextView contactoNick;
        TextView contactoMobile;
    }

    @Override
    public View getView(int position, View convertView, final ViewGroup parent)
    {

        View item = convertView;
        final ViewHolder holder;

        if(item == null)
        {
            LayoutInflater inflater = context.getLayoutInflater();
            item = inflater.inflate(R.layout.view_contact, null);
            holder = new ViewHolder();
            
            holder.contactoNick = (TextView)item.findViewById(R.id.ContactoNick);
            holder.contactoMobile = (TextView)item.findViewById(R.id.ContactoMobile);
            item.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)item.getTag();
        }

        Contacto contacto = datos.get(position);
        
        holder.contactoMobile.setText(contacto.getMobile());
        holder.contactoNick.setText(contacto.getNick());

        return(item);
    }

    public void anadirDatos(ArrayList<Contacto> datos) {
        this.datos.addAll(datos);
    }

}
